<template>
  <div class="box">
    
    <div class="swiper" ref="swiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="item in BannerList" :key="item.id">
          <img style="height: 450px" :src="item.imgUrl" alt="" />
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>

    <div>
      <div class="newsflash fr">
        <div class="news">
          <div class="news-hd">
            <span>尚品汇快报</span>
            <span>更多></span>
          </div>
          <div class="news-bd">
            <div>
              <span>【特惠】</span>
              <span>备战开学季 全民半价购数码</span>
            </div>
            <div>
              <span>【特惠】</span>
              <span>备战开学季 全民半价购数码</span>
            </div>
            <div>
              <span>【特惠】</span>
              <span>备战开学季 全民半价购数码</span>
            </div>
            <div>
              <span>【特惠】</span>
              <span>备战开学季 全民半价购数码</span>
            </div>
            <div>
              <span>【特惠】</span>
              <span>备战开学季 全民半价购数码</span>
            </div>
          </div>
          <div class="lifeservice">
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
            <div>话费</div>
          </div>
        </div>
      </div>
      <div>
        <img
          style="width: 252px; height: 74px"
          src="http://www.jk688.cn/upload/bargain.jpg"
          alt=""
        />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import Swiper from "swiper";
export default {
  created() {
    //触发vuex中的请求数据的方法
    this.$store.dispatch("getBannerList");
  },
  //在数据更新的时候在挂载上swiper
  watch: {
    BannerList: {
      handler() {
        //数据更新后 循环结束以后更新dom(有了结构以后再去执行这个)
        this.$nextTick(() => {
          new Swiper(this.$refs.swiper, {
            autoplay: true,
            loop: true,
            pagination: {
              el: ".swiper-pagination",
              clickable: true,
            },
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: "swiper-button-prev",
            },
          });
        });
      },
    },
  },
  updated() {
    console.log(this.BannerList);
  },
  computed: {
    ...mapState({
      BannerList: (state) => state.home.BannerList,
    }),
  },
};
</script>

<style lang="less" scoped>
.box {
  display: flex;
  justify-content: center;
  padding-left: 130px;

  .swiper {
    position: relative;
    height: 450px;
    width: 714px;
    margin-left: 100px;
    margin-right: 5px;
    overflow: hidden;
  }

  .swiper-button-prev {
    left: 0px !important;
  }

  .swiper-button-next {
    right: 0px !important;
  }

  img {
    margin-right: 10px;
  }

  .news {
    border: 1px solid #ccc;
    color: #666;
    width: 250px;
    margin-bottom: 10px;
    .news-hd {
      font-size: 14px;
      line-height: 32px;
      border-bottom: 1px dotted #ccc;
      padding: 0 15px;
      display: flex;
      justify-content: space-between;
    }

    .news-bd {
      padding: 10px;
      font-size: 14px;
    }

    .lifeservice {
      display: flex;
      flex-flow: wrap;
      justify-content: center;
      overflow: hidden;
      border-top: 1px solid #e4e4e4;
      div {
        text-align: center;
        height: 71px;
        width: 25%;
        font-size: 5px;
        margin-right: -1px;
        border-left: 1px solid #e4e4e4;
        border-bottom: 1px solid #e4e4e4;
      }
    }
  }
}
</style>